package com.fwj.gmall.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fwj.gmall.model.product.SkuInfo;
import com.fwj.gmall.product.service.SkuService;
import com.fwj.gmall.result.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/admin/product/")
@RestController
public class SkuController {

    @Autowired
    SkuService skuService;

    @ApiOperation("添加sku")
    @PostMapping("saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo) {
        skuService.saveSkuInfo(skuInfo);
        return Result.ok();
    }

    @ApiOperation("获取sku分页列表")
    @GetMapping("list/{page}/{limit}")
    public Result list(@PathVariable("page") Long page, @PathVariable("limit") Long limit) {
        IPage<SkuInfo> iPage = skuService.list(page, limit);
        return Result.ok(iPage);
    }

    @ApiOperation("上架")
    @GetMapping("onSale/{skuId}")
    public Result onSale(@PathVariable("skuId")Long skuId){
        skuService.onSale(skuId);
        return Result.ok();
    }

    @ApiOperation("下架")
    @GetMapping("cancelSale/{skuId}")
    public Result cancelSale(@PathVariable("skuId")Long skuId){
        skuService.cancelSale(skuId);
        return Result.ok();
    }

}
